home *** CD-ROM | disk | FTP | other *** search
/ 3D GFX / 3D GFX.iso / amiutils / i_l / irit5 / grapdrvs / xmtdrvs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-31  |  48.4 KB  |  1,252 lines

  1. /*****************************************************************************
  2. *   A motif interface driver.                             *
  3. *                                         *
  4. * Written by:  Offer Kaufman and Gershon Elber        Ver 0.1, November 1994.  *
  5. *****************************************************************************/
  6.  
  7. #ifdef __hpux
  8. typedef char *caddr_t;           /* Awful kludge. Let me know of a better way. */
  9. #endif /* __hpux */
  10.  
  11. #include <X11/Xlib.h>
  12. #include <X11/Xutil.h>
  13. #include <X11/cursorfont.h>
  14. #include <X11/Xresource.h>
  15.  
  16. #include <Xm/MainW.h>
  17. #include <Xm/PushB.h>
  18. #include <Xm/ToggleB.h>
  19. #include <Xm/RowColumn.h>
  20. #include <Xm/Label.h>
  21. #include <Xm/Scale.h>
  22. #include <Xm/Form.h>
  23.  
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include <math.h>
  27. #include <ctype.h>
  28.  
  29. #include "irit_sm.h"
  30. #include "genmat.h"
  31. #include "iritprsr.h"
  32. #include "irit_soc.h"
  33. #include "allocate.h"
  34. #include "attribut.h"
  35. #include "ip_cnvrt.h"
  36. #include "cagd_lib.h"
  37. #include "iritgrap.h"
  38. #include "xmtdrvs.h"
  39. #include "xgldrvs.h"
  40.  
  41. #define X11_FONT_NAME        "8x13"
  42.  
  43. #define DEFAULT_TRANS_WIDTH    200
  44. #define DEFAULT_TRANS_HEIGHT    500
  45.  
  46. #define TRANS_FRACTION        25
  47. #define STATE_FRACTION        24
  48.  
  49. /* X global specific staff goes here: */
  50. Display *XDisplay;
  51. int XScreen,
  52.     ViewHasSize,
  53.     ViewHasPos,
  54.     ViewPosX,
  55.     ViewPosY;
  56. unsigned int
  57.     MaxColors = IG_MAX_COLOR,
  58.     ViewBorderWidth,
  59.     ViewBackGroundPixel,
  60.     ViewBorderPixel,
  61.     ViewTextPixel,
  62.     ViewWidth = DEFAULT_VIEW_WIDTH,
  63.     ViewHeight = DEFAULT_VIEW_HEIGHT;
  64. Colormap XColorMap;
  65. GC XViewGraphContext;
  66.  
  67. Widget IGTopLevel;
  68. Window XRoot;
  69. static GC XTransGraphContext;
  70. static Visual *XVisual;
  71. static XFontStruct *XLoadedFont;
  72. static XColor
  73.     *TransCursorColor = NULL;
  74. XColor
  75.     BlackColor,
  76.     *ViewCursorColor = NULL;
  77. static unsigned long
  78.     TransBackGroundPixel,
  79.     TransBorderPixel,
  80.     TransTextPixel,
  81.     TransSubWinBackPixel,
  82.     TransSubWinBorderPixel;
  83. static int
  84.     XFontYOffsetToCenter = 0,
  85.     TransHasSize = FALSE,
  86.     TransHasPos = FALSE,
  87.     TransPosX = 0,
  88.     TransPosY = 0;
  89. static unsigned int
  90.     TransBorderWidth = 1,
  91.     TransSubWinBorderWidth = 1,
  92.     TransWidth = DEFAULT_TRANS_WIDTH,
  93.     TransHeight = DEFAULT_TRANS_HEIGHT;
  94.  
  95. /* X Colors to be used for viewed object (see also iritgrap.h): */
  96. static int XViewColorDefs[IG_MAX_COLOR + 1][3] =
  97. {
  98.     {     0,     0,     0 },  /* 0. IG_IRIT_BLACK */
  99.     {     0,     0, 43350 },  /* 1. IG_IRIT_BLUE */
  100.     {     0, 43350,     0 },  /* 2. IG_IRIT_GREEN */
  101.     {     0, 43350, 43350 },  /* 3. IG_IRIT_CYAN */
  102.     { 43350,     0,     0 },  /* 4. IG_IRIT_RED */
  103.     { 43350,     0, 43350 },  /* 5. IG_IRIT_MAGENTA */
  104.     { 43350, 43350,     0 },  /* 6. IG_IRIT_BROWN */
  105.     { 43350, 43350, 43350 },  /* 7. IG_IRIT_LIGHTGREY */
  106.     { 21675, 21675, 21675 },  /* 8. IG_IRIT_DARKGRAY */
  107.     { 21675, 21675, 65535 },  /* 9. IG_IRIT_LIGHTBLUE */
  108.     { 21675, 65535, 21675 },  /* 10. IG_IRIT_LIGHTGREEN */
  109.     { 21675, 65535, 65535 },  /* 11. IG_IRIT_LIGHTCYAN */
  110.     { 65535, 21675, 21675 },  /* 12. IG_IRIT_LIGHTRED */
  111.     { 65535, 21675, 65535 },  /* 13. IG_IRIT_LIGHTMAGENTA */
  112.     { 65535, 65535, 21675 },  /* 14. IG_IRIT_YELLOW */
  113.     { 65535, 65535, 65535 }   /* 15. IG_IRIT_WHITE */
  114. };
  115. XColor XViewColorsHigh[IG_MAX_COLOR + 1];
  116. XColor XViewColorsLow[IG_MAX_COLOR + 1];
  117. Window ViewWndw;
  118. static RealType OldSliderVal;
  119. static Widget ProjectionButton, DepthCueButton, StateForm, TransForm,
  120.     LineWidthLabel, ChangeFactorLabel, FineNessLabel,
  121.     NormalLenLabel, NumOfIsolinesLabel;
  122.  
  123. static void CreateControlPanel(Widget TopLevel);
  124. static char *ReadOneXDefault(char *Entry);
  125. static void ReadXDefaults(void);
  126. static void CreatePopupWindow(Widget w);
  127. static void TransformCB(Widget w, int state);
  128. static void SetCB(Widget w, int State, XmScaleCallbackStruct *CallData);
  129. static int ExposeCB(Widget w); 
  130. static void ScaleCB(Widget w, IGGraphicEventType EventType);
  131. static void DragCB(Widget w, IGGraphicEventType EventType);
  132.  
  133. /*****************************************************************************
  134. * DESCRIPTION:                                                               M
  135. *   Pop up all windows, read input and display.                     M
  136. *                                                                            *
  137. * PARAMETERS:                                                                M
  138. *   argc, argv:  command line parameters ( *.dat files )                     M
  139. *                                                                            *
  140. * RETURN VALUE:                                                              M
  141. *   void                                                                     M
  142. *                                                                            *
  143. * KEYWORDS:                                                                  M
  144. *   main                                            M
  145. *****************************************************************************/
  146. void main(int argc, char **argv)
  147. {
  148.     int i;
  149.     XGCValues Values;
  150.     XtAppContext App;
  151.  
  152.     IGConfigureGlobals(argv[0], argc, argv);
  153.  
  154.     /* Lets see if we can get access to the X server before we even start: */
  155.     if ((XDisplay = (Display *) XOpenDisplay(NULL)) == NULL) {
  156.     fprintf(stderr, "xmtdrvs: Failed to access X server, abored.\n");
  157.         exit(-1);
  158.     }
  159.     if ((XLoadedFont = XLoadQueryFont(XDisplay, X11_FONT_NAME)) == NULL) {
  160.     fprintf(stderr,
  161.         "%s: Failed to load required X font \"%s\", aborted.\n",
  162.         argv[0], X11_FONT_NAME);
  163.     exit(-1);
  164.     }
  165.     XFontYOffsetToCenter = (XLoadedFont -> ascent - XLoadedFont -> descent + 1)
  166.                                        / 2;
  167.  
  168.     XScreen = DefaultScreen(XDisplay);
  169.     XRoot = RootWindow(XDisplay, XScreen);
  170.     XColorMap = DefaultColormap(XDisplay, XScreen);
  171.     XVisual = DefaultVisual(XDisplay, XScreen);
  172.     Values.foreground = WhitePixel(XDisplay, XScreen);
  173.     Values.background = BlackPixel(XDisplay, XScreen);
  174.     Values.font = XLoadedFont -> fid;
  175.     XTransGraphContext = XCreateGC(XDisplay, XRoot,
  176.                    GCForeground | GCBackground | GCFont,
  177.                    &Values);
  178.     XViewGraphContext = XCreateGC(XDisplay, XRoot,
  179.                   GCForeground | GCBackground, &Values);
  180.     
  181.     if (XDisplay->db == NULL)
  182.     XGetDefault(XDisplay, "", "");
  183.     ReadXDefaults();
  184.  
  185.     for (i = 0; i <= IG_MAX_COLOR; i++) {
  186.     XViewColorsHigh[i].red   = XViewColorDefs[i][0];
  187.     XViewColorsHigh[i].green = XViewColorDefs[i][1];
  188.     XViewColorsHigh[i].blue  = XViewColorDefs[i][2];
  189.  
  190.     /* If fails to allocate the color - take WHITE instead. */
  191.     if (!XAllocColor(XDisplay, XColorMap, &XViewColorsHigh[i]))
  192.         XViewColorsHigh[i].pixel = WhitePixel(XDisplay, XScreen);
  193.  
  194.     XViewColorsLow[i].red   = XViewColorDefs[i][0] / 2;
  195.     XViewColorsLow[i].green = XViewColorDefs[i][1] / 2;
  196.     XViewColorsLow[i].blue  = XViewColorDefs[i][2] / 2;
  197.  
  198.     /* If fails to allocate the color - take WHITE instead. */
  199.     if (!XAllocColor(XDisplay, XColorMap, &XViewColorsLow[i]))
  200.         XViewColorsLow[i].pixel = WhitePixel(XDisplay, XScreen);
  201.     }
  202.  
  203.     SetViewWindow(argc, argv);
  204.  
  205.     sleep(1); /* Some systems get confused if we draw immediately. */
  206.   
  207.     IGRedrawViewWindow();
  208.  
  209.     IGTopLevel = XtVaAppInitialize(&App, argv[0], NULL, 0,
  210.                    &argc, argv, NULL, NULL);
  211.     if (TransHasSize)
  212.     XtVaSetValues(IGTopLevel, XmNheight, TransHeight,
  213.               XmNwidth, TransWidth, NULL);
  214.  
  215.     CreateControlPanel(IGTopLevel);
  216.     CreatePopupWindow(IGTopLevel);
  217.     CreateAnimation(IGTopLevel);
  218.  
  219.     XtAppAddWorkProc(App, (XtWorkProc) ExposeCB, NULL);
  220.  
  221.     XtRealizeWidget(IGTopLevel);
  222.     XtAppMainLoop(App);
  223. }
  224.  
  225. /*****************************************************************************
  226. * DESCRIPTION:                                                               M
  227. *   Handles the state events.                              M
  228. *                                                                            *
  229. * PARAMETERS:                                                                M
  230. *   State:    State to be treated.                             M
  231. *   Refresh:  Wether state change requires screen refreshing.                M
  232. *                                                                            *
  233. * RETURN VALUE:                                                              M
  234. *   UpdateView                                                    M
  235. *                                                                            *
  236. * KEYWORDS:                                                                  M
  237. *    IGHandleState                                        M
  238. *****************************************************************************/
  239. int IGHandleState(int State, int Refresh)
  240. {
  241.     int UpdateView = TRUE;
  242.  
  243.     UpdateView = IGDefaultStateHandler(State, Refresh);
  244.  
  245.     XtDestroyWidget(StateForm); 
  246.     CreatePopupWindow(IGTopLevel);
  247.  
  248.     return UpdateView;
  249. }
  250.  
  251. /*****************************************************************************
  252. * DESCRIPTION:                                                               *
  253. *   Creates Motif Based Control Panel.                          *
  254. *                                                                            *
  255. * PARAMETERS:                                                                *
  256. *   w:  Parent widget.                                                 *
  257. *                                                                            *
  258. * RETURN VALUE:                                                              *
  259. *   void                                                                     *
  260. *****************************************************************************/
  261. static void CreateControlPanel(Widget TopLevel)
  262. {
  263.     static char *SlideTitle[] = {
  264.     " PERSPECTIVE",
  265.     " ROTATE",
  266.     " TRANSLATE",
  267.     " SCALE",
  268.     " FAR/NEAR CLIP",
  269.     " MATRIX",
  270.     " PROJECTIONS"
  271.     };
  272.     static char SlideLabel[][2] = {
  273.     "Z",
  274.     "X",
  275.     "Y",
  276.     "Z",
  277.     "X",
  278.     "Y",
  279.     "Z",
  280.     " ",
  281.     "N",
  282.     "F"
  283.     };    
  284.     Widget MainW, Form, SubForm, Label, Button, Scale;
  285.     int i,
  286.     Pos = 0,
  287.     t = 0;
  288.     IGGraphicEventType EventType;
  289.  
  290.     MainW = XtVaCreateManagedWidget("TransWindow",
  291.                     xmMainWindowWidgetClass, TopLevel,
  292.                     NULL);
  293.     TransForm = XtVaCreateManagedWidget("TransForm",
  294.                     xmFormWidgetClass,   MainW,
  295.                     XmNtopAttachment,    XmATTACH_WIDGET,
  296.                     XmNtopWidget,          MainW,
  297.                     XmNbottomAttachment, XmATTACH_WIDGET,
  298.                     XmNbottomWidget,     MainW,  
  299.                     XmNleftAttachment,   XmATTACH_WIDGET,
  300.                     XmNleftWidget,          MainW,
  301.                     XmNrightAttachment,  XmATTACH_WIDGET,
  302.                     XmNrightWidget,      MainW,
  303.                     XmNfractionBase,     TRANS_FRACTION,
  304.                     NULL);
  305.  
  306.     /* Construct all slide bars (Scales) */
  307.     for (i = 0, EventType = IG_EVENT_PERS_ORTHO_Z; i < 10; i++, EventType++) {
  308.         if (i == 0 || i == 1 || i == 4 || i == 7 || i == 8) {
  309.             Form = CreateSubForm(TransForm, Pos++); 
  310.             Label = XtVaCreateManagedWidget(SlideTitle[t++],
  311.                         xmLabelWidgetClass,  Form,
  312.                         XmNleftAttachment,   XmATTACH_FORM,
  313.                         XmNrightAttachment,  XmATTACH_FORM,
  314.                         NULL);              
  315.         }
  316.         Form = CreateSubForm(TransForm, Pos++);     
  317.         Label = XtVaCreateManagedWidget(SlideLabel[i],
  318.                     xmLabelWidgetClass, Form,
  319.                     NULL);
  320.         Scale = XtVaCreateManagedWidget("Scale",
  321.                     xmScaleWidgetClass,  Form,
  322.                     XmNorientation,         XmHORIZONTAL,
  323.                     XmNminimum,          -100,
  324.                     XmNrightAttachment,  XmATTACH_FORM,
  325.                     XmNleftAttachment,   XmATTACH_WIDGET,
  326.                     XmNleftWidget,       Label,
  327.                     XmNmaximum,         100,
  328.                     NULL);    
  329.         XtAddCallback(Scale, XmNvalueChangedCallback,
  330.               (XTC) ScaleCB, (XTP) EventType);
  331.         XtAddCallback(Scale, XmNdragCallback, (XTC) DragCB, (XTP) EventType);
  332.     }
  333.     
  334.     Form = CreateSubForm(TransForm, Pos++); 
  335.     Label = XtVaCreateManagedWidget(SlideTitle[t++],
  336.                     xmLabelWidgetClass,      Form,
  337.                     XmNleftAttachment,      XmATTACH_FORM,
  338.                     XmNrightAttachment,      XmATTACH_FORM,
  339.                     NULL);
  340.  
  341.     Form = CreateSubForm(TransForm, Pos++);         
  342.     SubForm = XtVaCreateManagedWidget("MatrixOpFoundation",
  343.                       xmFormWidgetClass,      Form,
  344.                       XmNleftAttachment,      XmATTACH_FORM,
  345.                       XmNrightAttachment,     XmATTACH_FORM,
  346.                       XmNfractionBase,       3,
  347.                       NULL);
  348.                
  349.     Button = XtVaCreateManagedWidget("Save",
  350.                      xmPushButtonWidgetClass,SubForm, 
  351.                      XmNleftAttachment,      XmATTACH_POSITION,
  352.                      XmNleftPosition,        0,
  353.                      XmNrightAttachment,     XmATTACH_POSITION,
  354.                      XmNrightPosition,       1,
  355.                      NULL);
  356.     XtAddCallback(Button, XmNactivateCallback,
  357.           (XTC) TransformCB, (XTP) IG_EVENT_SAVE_MATRIX);
  358.  
  359.     Button = XtVaCreateManagedWidget("Push",
  360.                      xmPushButtonWidgetClass,SubForm, 
  361.                      XmNleftAttachment,      XmATTACH_POSITION,
  362.                      XmNleftPosition,        1,
  363.                      XmNrightAttachment,     XmATTACH_POSITION,
  364.                      XmNrightPosition,       2,
  365.                      NULL);
  366.     XtAddCallback(Button, XmNactivateCallback,
  367.           (XTC) TransformCB, (XTP) IG_EVENT_PUSH_MATRIX);
  368.  
  369.     Button = XtVaCreateManagedWidget("Pop",
  370.                      xmPushButtonWidgetClass,SubForm, 
  371.                      XmNleftAttachment,      XmATTACH_POSITION,
  372.                      XmNleftPosition,        2,
  373.                      XmNrightAttachment,     XmATTACH_POSITION,
  374.                      XmNrightPosition,       3,
  375.                      NULL);
  376.     XtAddCallback(Button, XmNactivateCallback,
  377.           (XTC) TransformCB, (XTP) IG_EVENT_POP_MATRIX);
  378.  
  379.     Pos++;
  380.     Form = CreateSubForm(TransForm, Pos++);
  381.     SubForm = XtVaCreateManagedWidget("SubForm",
  382.                       xmFormWidgetClass,       Form,
  383.                       XmNrightAttachment,      XmATTACH_FORM,
  384.                       XmNleftAttachment,       XmATTACH_FORM,
  385.                       XmNfractionBase,         2,
  386.                       NULL);
  387.  
  388.     Button = XtVaCreateManagedWidget("Top",
  389.                      xmPushButtonWidgetClass,SubForm,
  390.                      XmNleftAttachment,      XmATTACH_POSITION,
  391.                      XmNleftPosition,        0,
  392.                      XmNrightAttachment,     XmATTACH_POSITION,
  393.                      XmNrightPosition,       1,
  394.                      NULL);
  395.     XtAddCallback(Button, XmNactivateCallback,
  396.           (XTC) SetCB, (XTP)IG_STATE_VIEW_TOP);
  397.  
  398.     Button = XtVaCreateManagedWidget("Side",
  399.                      xmPushButtonWidgetClass,SubForm,
  400.                      XmNleftAttachment,      XmATTACH_POSITION,
  401.                      XmNleftPosition,          1,
  402.                      XmNrightAttachment,     XmATTACH_POSITION,
  403.                      XmNrightPosition,          2,
  404.                      NULL);
  405.  
  406.     Form = CreateSubForm(TransForm, Pos++);
  407.     SubForm = XtVaCreateManagedWidget("Subform",
  408.                       xmFormWidgetClass,     Form,
  409.                       XmNrightAttachment,    XmATTACH_FORM,
  410.                       XmNleftAttachment,     XmATTACH_FORM,
  411.                       XmNfractionBase,         2,
  412.                       NULL);
  413.     XtAddCallback(Button, XmNactivateCallback,
  414.           (XTC) SetCB, (XTP)IG_STATE_VIEW_SIDE);
  415.  
  416.     Button = XtVaCreateManagedWidget("Front",
  417.                      xmPushButtonWidgetClass,SubForm,
  418.                      XmNleftAttachment,      XmATTACH_POSITION,
  419.                      XmNleftPosition,          0,
  420.                      XmNrightAttachment,     XmATTACH_POSITION,
  421.                      XmNrightPosition,          1,
  422.                      NULL);
  423.     XtAddCallback(Button, XmNactivateCallback,
  424.           (XTC) SetCB, (XTP)IG_STATE_VIEW_FRONT);
  425.  
  426.     Button = XtVaCreateManagedWidget("Iso",
  427.                      xmPushButtonWidgetClass,SubForm,
  428.                      XmNleftAttachment,      XmATTACH_POSITION,
  429.                      XmNleftPosition,          1,
  430.                      XmNrightAttachment,     XmATTACH_POSITION,
  431.                      XmNrightPosition,          2,
  432.                      NULL);
  433.     XtAddCallback(Button, XmNactivateCallback,
  434.           (XTC) SetCB, (XTP)IG_STATE_VIEW_ISOMETRY);
  435.  
  436.     Pos++;
  437.     Form = CreateSubForm(TransForm, Pos++);        
  438.     Button = XtVaCreateManagedWidget("Animation",
  439.                      xmPushButtonWidgetClass,    Form, 
  440.                      XmNleftAttachment,     XmATTACH_FORM,
  441.                      XmNrightAttachment,     XmATTACH_FORM,
  442.                      NULL);
  443.     XtAddCallback(Button, XmNactivateCallback,
  444.           (XTC) AnimationCB, (XTP) IG_EVENT_ANIMATION);
  445.  
  446.     Form = CreateSubForm(TransForm, Pos++);        
  447.     Button = XtVaCreateManagedWidget("Environment",
  448.                      xmPushButtonWidgetClass,     Form, 
  449.                      XmNleftAttachment,     XmATTACH_FORM,
  450.                      XmNrightAttachment,     XmATTACH_FORM,
  451.                      NULL);
  452.     XtAddCallback(Button, XmNactivateCallback,
  453.           (XTC) TransformCB, (XTP) IG_EVENT_STATE);
  454.  
  455.     Pos++;
  456.     Form = CreateSubForm(TransForm, Pos++);        
  457.     Button = XtVaCreateManagedWidget("Quit",
  458.                      xmPushButtonWidgetClass,     Form, 
  459.                      XmNleftAttachment,     XmATTACH_FORM,
  460.                      XmNrightAttachment,     XmATTACH_FORM,
  461.                      NULL);
  462.     XtAddCallback(Button, XmNactivateCallback,
  463.           (XTC) TransformCB, (XTP) IG_EVENT_QUIT);
  464.  
  465.     if (TRANS_FRACTION < Pos)
  466.     fprintf(stderr,
  467.         "Initialization of Transformation is not complete (%d).\n",
  468.         Pos);
  469. }
  470.  
  471. /*****************************************************************************
  472. * DESCRIPTION:                                                               *
  473. *   Create and activate pop up window.                       *
  474. *                                                                            *
  475. * PARAMETERS:                                                                *
  476. *   w:  Calling widget.                                               *
  477. *                                                                            *
  478. * RETURN VALUE:                                                              *
  479. *   void                                                                     *
  480. *****************************************************************************/
  481. static void CreatePopupWindow(Widget w)
  482. {
  483.     int Pos = 0;
  484.     char NewLabel[30];
  485.     Arg args[10];
  486.  
  487.     XtSetArg(args[0], XmNfractionBase, STATE_FRACTION);
  488.     StateForm = XmCreateFormDialog(w, "StateMenu", args, 1);
  489.  
  490.     AddButton(StateForm, IGGlblTransformMode == IG_TRANS_OBJECT ?
  491.           "Object Trans" : "Screen Trans", Pos++,
  492.           (XTC) TransformCB, (XTP) IG_EVENT_SCR_OBJ_TGL);
  493.     DepthCueButton = AddButton(StateForm,
  494.                    IGGlblDepthCue ? "Depth Cue On"
  495.                           : "No Depth Cue",
  496.                    Pos++, (XTC) TransformCB,
  497.                    (XTP) IG_EVENT_DEPTH_CUE);
  498.     ProjectionButton = AddButton(StateForm,
  499.                  IGGlblViewMode == IG_VIEW_PERSPECTIVE ?
  500.                      "Perspective" : "Orthographic",
  501.                  Pos++, (XTC) TransformCB,
  502.                  (XTP) IG_EVENT_PERS_ORTHO_TGL);
  503.     AddButton(StateForm, IGGlblDrawSolid ? "Draw Solid" : "Draw Wireframe",
  504.           Pos++, (XTC) SetCB, (XTP) IG_STATE_DRAW_SOLID);
  505.     AddButton(StateForm, IGGlblBackFaceCull ? "Cull Back Face"
  506.                         : "No Cull Back Face",
  507.           Pos++, (XTC) SetCB, (XTP) IG_STATE_BACK_FACE_CULL);
  508.     AddButton(StateForm, IGGlblDoDoubleBuffer ? "Double Buffer"
  509.                           : "Single Buffer",
  510.                Pos++, (XTC) SetCB, (XTP) IG_STATE_DOUBLE_BUFFER);
  511.     AddButton(StateForm, IGGlblAntiAliasing ? "Anti Aliasing"
  512.                         : "No Anti Aliasing",
  513.           Pos++, (XTC) SetCB, (XTP) IG_STATE_ANTI_ALIASING);
  514.     AddButton(StateForm, IGGlblDrawInternal ? "Draw Internal Edges"
  515.                         : "No Internal Edges",
  516.           Pos++, (XTC) SetCB, (XTP) IG_STATE_DRAW_INTERNAL);
  517.     AddButton(StateForm, IGGlblDrawVNormal ? "Draw Vrtx Normals"
  518.                        : "No Vrtx Normals",
  519.           Pos++, (XTC) SetCB, (XTP) IG_STATE_DRAW_VNORMAL);
  520.     AddButton(StateForm, IGGlblDrawPNormal ? "Draw Poly Normals"
  521.                        : "No Poly Normals",
  522.           Pos++, (XTC) SetCB, (XTP) IG_STATE_DRAW_PNORMAL);
  523.     AddButton(StateForm, IGGlblDrawSurfaceMesh ? "Draw Surface Mesh"
  524.                            : "No Surface Mesh",
  525.           Pos++, (XTC) SetCB, (XTP) IG_STATE_DRAW_SRF_MESH);
  526.     AddButton(StateForm, IGGlblDrawSurfacePoly ? "Surface Poly"
  527.                            : "Surface Isolines",
  528.           Pos++, (XTC) SetCB, (XTP) IG_STATE_DRAW_SRF_POLY);
  529.     AddButton(StateForm, IGGlblFourPerFlat ? "Four Per Flat" : "Two Per Flat",
  530.           Pos++, (XTC) SetCB, (XTP) IG_STATE_FOUR_PER_FLAT);
  531.  
  532.     sprintf(NewLabel, "Normal Len %2.2f", IGGlblNormalLen);
  533.     NormalLenLabel = AddLabel(StateForm, NewLabel, Pos++);
  534.     AddSlide(StateForm, Pos++, 100,
  535.          (XTC) SetCB, (XTP) IG_STATE_LONGER_VECTORS);
  536.     sprintf(NewLabel, "Lines Width %d", IGGlblLineWidth);
  537.     LineWidthLabel = AddLabel(StateForm, NewLabel, Pos++);
  538.     AddSlide(StateForm, Pos++, 20,
  539.          (XTC) SetCB, (XTP) IG_STATE_WIDER_LINES);
  540.     sprintf(NewLabel, "Sensitivity %2.2f", IGGlblChangeFactor);
  541.     ChangeFactorLabel = AddLabel(StateForm, NewLabel, Pos++);
  542.     AddSlide(StateForm, Pos++, 100,
  543.          (XTC) SetCB, (XTP) IG_STATE_MORE_SENSITIVE);
  544.     sprintf(NewLabel, "Isolines %2d", IGGlblNumOfIsolines);
  545.     NumOfIsolinesLabel = AddLabel(StateForm, NewLabel, Pos++);
  546.     AddSlide(StateForm, Pos++, 1000,
  547.          (XTC) SetCB, (XTP) IG_STATE_MORE_ISOLINES);
  548.     sprintf(NewLabel, "Samples %2d", IGGlblSamplesPerCurve);
  549.     FineNessLabel = AddLabel(StateForm, NewLabel, Pos++);
  550.     AddSlide(StateForm, Pos++, 1000,
  551.          (XTC) SetCB, (XTP) IG_STATE_FINER_APPROX);
  552.  
  553.     AddButton(StateForm, "Dismiss", Pos++, (XTC) SetCB, (XTP) IG_STATE_OOPS);
  554.  
  555.     if (STATE_FRACTION < Pos)
  556.     fprintf(stderr,
  557.         "Initialization of Popup State is not complete (%d).\n",
  558.         Pos);
  559. }
  560.  
  561. /*****************************************************************************
  562. * DESCRIPTION:                                                               *
  563. *   Handles transformation window Buttons.                       *
  564. *                                                                            *
  565. * PARAMETERS:                                                                *
  566. *   w:      Calling widget.                                               *
  567. *   State:  State represented by the widget.                         *
  568. *                                                                            *
  569. * RETURN VALUE:                                                              *
  570. *   void                                                                     *
  571. *****************************************************************************/
  572. static void TransformCB(Widget w, int State)
  573. {
  574.     Position MainWindowX, MainWindowY;
  575.     Dimension MainWindowW;
  576.  
  577.     switch(State) {
  578.     case IG_EVENT_DEPTH_CUE:
  579.         IGGlblDepthCue = !IGGlblDepthCue;
  580.         SetLabel(w, IGGlblDepthCue ? "Depth Cue On" : "No Depth Cue");
  581.         IGRedrawViewWindow();
  582.         break;
  583.     case IG_EVENT_SCR_OBJ_TGL:
  584.         IGGlblTransformMode = IGGlblTransformMode == IG_TRANS_OBJECT ? 
  585.                         IG_TRANS_SCREEN : IG_TRANS_OBJECT;
  586.         SetLabel(w, IGGlblTransformMode == IG_TRANS_SCREEN ? 
  587.                          "Screen Trans" :"Object Trans");
  588.         break;
  589.     case IG_EVENT_PERS_ORTHO_TGL:
  590.         IGGlblViewMode = IGGlblViewMode == IG_VIEW_PERSPECTIVE ?
  591.                    IG_VIEW_ORTHOGRAPHIC : IG_VIEW_PERSPECTIVE;
  592.         IGRedrawViewWindow();
  593.         SetLabel(w, IGGlblViewMode == IG_VIEW_PERSPECTIVE ?
  594.                          "Perspective": "Orthographic");
  595.         break;
  596.     case IG_EVENT_STATE:
  597.         XtVaGetValues(IGTopLevel,
  598.               XmNwidth, &MainWindowW,
  599.               XmNx, &MainWindowX,
  600.               XmNy, &MainWindowY,
  601.               NULL);
  602.         XtVaSetValues(StateForm,
  603.               XmNdefaultPosition, FALSE,
  604.               XmNx, MainWindowX + MainWindowW + 16,
  605.               XmNy, MainWindowY,
  606.               NULL); 
  607.         XtManageChild(StateForm); 
  608.         break;    
  609.     case IG_EVENT_QUIT:
  610.         if (!IGGlblStandAlone)
  611.         IritPrsrClntCloseConnect(IGGlblPrgmInput, IGGlblPrgmOutput);
  612.         exit(0);
  613.     default:
  614.         if(IGProcessEvent(State, 1)) 
  615.         IGRedrawViewWindow();
  616.     }
  617. }       
  618.  
  619. /*****************************************************************************
  620. * DESCRIPTION:                                                               *
  621. *   Treat exposure event.                               *
  622. *                                                                            *
  623. * PARAMETERS:                                                                *
  624. *   w:  Calling widget.                                                      *
  625. *                                                                            *
  626. * RETURN VALUE:                                                              *
  627. *   FALSE:  Keep the working function alive.                            *
  628. *****************************************************************************/
  629. static int ExposeCB(Widget w)
  630. {
  631.     XEvent Event;
  632.     XWindowAttributes WinAttr;
  633.  
  634.     if (!IGGlblStandAlone &&
  635.         IGReadObjectsFromSocket(IGGlblViewMode, &IGGlblDisplayList))
  636.         IGRedrawViewWindow();
  637.  
  638.     IGHandleInternalEvents();
  639.  
  640.     if (XPending(XDisplay)) {
  641.     XNextEvent(XDisplay, &Event);
  642.  
  643.     switch (Event.type) {
  644.         case Expose:      /* Get rid of all Expose events in the queue. */
  645.         while (XCheckWindowEvent(XDisplay, Event.xbutton.window,
  646.                      ExposureMask, &Event));
  647.         if (Event.xbutton.window == ViewWndw) {
  648.             XGetWindowAttributes(XDisplay, ViewWndw, &WinAttr);
  649.             ViewWidth = WinAttr.width;
  650.             ViewHeight = WinAttr.height;
  651.             IGRedrawViewWindow();
  652.         }
  653.         case ResizeRequest:/* Get rid of all Resize events in the queue.*/
  654.         while (XCheckWindowEvent(XDisplay, Event.xbutton.window,
  655.                      ResizeRedirectMask, &Event));
  656.         if (Event.xbutton.window == ViewWndw) {
  657.             XGetWindowAttributes(XDisplay, ViewWndw, &WinAttr);
  658.             ViewWidth = WinAttr.width;
  659.             ViewHeight = WinAttr.height;
  660.             IGRedrawViewWindow();
  661.         }
  662.     }
  663.     }
  664.  
  665.     IritSleep(10);
  666.  
  667.     return FALSE;     /* Make sure it will be called next time we are idle. */
  668. }
  669.  
  670. /*****************************************************************************
  671. * DESCRIPTION:                                                               *
  672. *   Responds to settings commands.                           *
  673. *                                                                            *
  674. * PARAMETERS:                                                                *
  675. *   w:         Calling widget.                                              *
  676. *   State:     State represented by widget.                     *
  677. *   CallData:  For detecting drag/click action on scales.             *
  678. *                                                                            *
  679. * RETURN VALUE:                                                              *
  680. *   void                                                                     *
  681. *****************************************************************************/
  682. static void SetCB(Widget w, int State, XmScaleCallbackStruct *CallData)
  683. {    
  684.     int Value, NewValue;
  685.     char NewLabel[30];
  686.  
  687.     switch (State) {
  688.     case IG_STATE_LONGER_VECTORS: 
  689.             XmScaleGetValue(w, &NewValue);
  690.         IGGlblNormalLen *= (float) exp(IGGlblChangeFactor *
  691.                     (NewValue - OldSliderVal) / 75);
  692.         IGRedrawViewWindow();
  693.         sprintf(NewLabel, "Normal Len %2.2f", IGGlblNormalLen);
  694.         SetLabel(NormalLenLabel, NewLabel);
  695.         break;
  696.     case IG_STATE_OOPS:
  697.         XtUnmanageChild(StateForm); 
  698.         break;
  699.     case IG_STATE_MORE_SENSITIVE:
  700.         XmScaleGetValue(w, &NewValue);
  701.         IGGlblChangeFactor *= (float) exp((NewValue - OldSliderVal) / 75);
  702.         sprintf(NewLabel, "Sensitivity %2.2f", IGGlblChangeFactor);
  703.         SetLabel(ChangeFactorLabel, NewLabel);
  704.         break;
  705.     case IG_STATE_DRAW_SOLID:
  706.         IGGlblDrawSolid = !IGGlblDrawSolid;
  707.         SetLabel(w, IGGlblDrawSolid ? "Draw Solid" : "Draw Wireframe");
  708.  
  709.         /* And disable depth cueing. */
  710.         IGGlblDepthCue = TRUE;
  711.     case IG_STATE_DEPTH_CUE:
  712.         IGGlblDepthCue = !IGGlblDepthCue;
  713.         SetLabel(DepthCueButton,
  714.              IGGlblDepthCue ? "Depth Cue On" : "No Depth Cue");
  715.         IGRedrawViewWindow();
  716.         break;
  717.     case IG_STATE_BACK_FACE_CULL:
  718.         IGGlblBackFaceCull = !IGGlblBackFaceCull;
  719.         SetLabel(w, IGGlblBackFaceCull ? "Cull Back Face"
  720.                        : "No Cull Back Face");
  721.         IGRedrawViewWindow();
  722.         break;    
  723.     case IG_STATE_DOUBLE_BUFFER: 
  724.         IGGlblDoDoubleBuffer = !IGGlblDoDoubleBuffer;
  725.         SetLabel(w, IGGlblDoDoubleBuffer ? "Double Buffer"
  726.                          : "Single Buffer");
  727.         break;
  728.     case IG_STATE_WIDER_LINES:
  729.         XmScaleGetValue(w, &NewValue);
  730.         IGGlblLineWidth += (int) ((NewValue - OldSliderVal) *
  731.                       IGGlblChangeFactor);
  732.         IGGlblLineWidth = (IGGlblLineWidth > 1) ? IGGlblLineWidth : 1;
  733.         sprintf(NewLabel, "Lines Width %d", IGGlblLineWidth);
  734.         SetLabel(LineWidthLabel, NewLabel);
  735.         IGRedrawViewWindow();
  736.         break;
  737.     case IG_STATE_MORE_ISOLINES:
  738.         XmScaleGetValue(w, &NewValue);
  739.         Value = (int) (IGGlblNumOfIsolines * 
  740.                exp(IGGlblChangeFactor * (NewValue - OldSliderVal)
  741.                                    / 1000.0));
  742.         IGGlblNumOfIsolines = Value != IGGlblNumOfIsolines ? Value :
  743.           Value + SIGN(NewValue - OldSliderVal);
  744.         IGGlblNumOfIsolines = IGGlblNumOfIsolines > 2 ?
  745.                               IGGlblNumOfIsolines : 2;
  746.         sprintf(NewLabel, "Isolines %d", IGGlblNumOfIsolines);
  747.         SetLabel(NumOfIsolinesLabel, NewLabel);
  748.         IGActiveListFreeNamedAttribute("_isoline");
  749.         IGRedrawViewWindow();
  750.         break;
  751.     case IG_STATE_FINER_APPROX:
  752.         XmScaleGetValue(w, &NewValue);
  753.         Value = (int) (IGGlblSamplesPerCurve *
  754.                exp(IGGlblChangeFactor * (NewValue - OldSliderVal)
  755.                                    / 1000.0));
  756.         IGGlblSamplesPerCurve = Value != IGGlblSamplesPerCurve ?
  757.                 Value :    Value + SIGN(NewValue - OldSliderVal);
  758.         IGGlblSamplesPerCurve = IGGlblSamplesPerCurve > 2 ?
  759.                             IGGlblSamplesPerCurve : 2;
  760.         
  761.         Value = (int) (IGGlblFineNess *
  762.                exp( IGGlblChangeFactor * (NewValue - OldSliderVal)
  763.                                    / 1000.0));
  764.         IGGlblFineNess = Value != IGGlblFineNess ?
  765.                 Value : Value + SIGN(NewValue - OldSliderVal);
  766.         if (IGGlblFineNess < 2.0)
  767.             IGGlblFineNess = 2.0;
  768.  
  769.         sprintf(NewLabel, "Samples %2d", IGGlblSamplesPerCurve);
  770.         SetLabel(FineNessLabel, NewLabel);
  771.         IGActiveListFreeNamedAttribute("_polygons");
  772.         IGActiveListFreeNamedAttribute("_isoline");
  773.         IGRedrawViewWindow();
  774.         break;
  775.     case IG_STATE_ANTI_ALIASING:
  776.         IGGlblAntiAliasing = !IGGlblAntiAliasing;
  777.         SetLabel(w, IGGlblAntiAliasing ? "Anti Aliasing"
  778.                        : "No Anti Aliasing");
  779.         IGRedrawViewWindow();
  780.         break;
  781.     case IG_STATE_DRAW_INTERNAL:
  782.         IGDefaultStateHandler(State, FALSE);
  783.         SetLabel(w, IGGlblDrawInternal ? "Draw Internal Edges"
  784.                        : "No Internal Edges");
  785.         IGRedrawViewWindow();
  786.         break;
  787.     case IG_STATE_DRAW_VNORMAL:
  788.         IGDefaultStateHandler(State, FALSE);    
  789.         SetLabel(w, IGGlblDrawVNormal ? "Draw Vrtx Normals"
  790.                       : "No Vrtx Normals");
  791.         IGRedrawViewWindow();
  792.         break;
  793.     case IG_STATE_DRAW_PNORMAL:
  794.         IGDefaultStateHandler(State, FALSE);
  795.         SetLabel(w, IGGlblDrawPNormal ? "Draw Poly Normals"
  796.                       : "No Poly Normals"); 
  797.         IGRedrawViewWindow();
  798.         break;
  799.     case IG_STATE_DRAW_SRF_MESH:
  800.         IGDefaultStateHandler(State, FALSE);
  801.         SetLabel(w, IGGlblDrawSurfaceMesh ? "Draw Surface Mesh"
  802.                           : "No Surface Mesh");
  803.         IGRedrawViewWindow();
  804.         break;
  805.     case IG_STATE_DRAW_SRF_POLY:
  806.         IGDefaultStateHandler(State, FALSE); 
  807.         SetLabel(w, IGGlblDrawSurfacePoly ? "Surface Poly"
  808.                           : "Surface Isolines"); 
  809.         IGRedrawViewWindow();
  810.         break;
  811.     case IG_STATE_FOUR_PER_FLAT:
  812.         IGDefaultStateHandler(State, FALSE);
  813.         SetLabel(w, IGGlblFourPerFlat ? "Four Per Flat" : "Two Per Flat");
  814.         IGRedrawViewWindow();
  815.         break;
  816.     case IG_STATE_VIEW_FRONT:
  817.     case IG_STATE_VIEW_SIDE:
  818.     case IG_STATE_VIEW_TOP:
  819.     case IG_STATE_VIEW_ISOMETRY:
  820.         SetLabel(ProjectionButton, "Orthographic");
  821.     default:
  822.         IGDefaultStateHandler(State, FALSE);
  823.         IGRedrawViewWindow();
  824.     }
  825.  
  826.     if (CallData -> reason == XmCR_DRAG) 
  827.     OldSliderVal = NewValue;
  828.  
  829.     if (CallData -> reason == XmCR_VALUE_CHANGED) {
  830.         XmScaleSetValue(w, 0);
  831.     OldSliderVal =0;
  832.     }
  833. }  
  834. /*****************************************************************************
  835. * DESCRIPTION:                                                               *
  836. *   Treats scales mouse-click movements.                       *
  837. *                                                                            *
  838. * PARAMETERS:                                                                *
  839. *   w:          Calling scale.                                         *
  840. *   EventType:  Event represented by the calling scale.                 *
  841. *                                                                            *
  842. * RETURN VALUE:                                                              *
  843. *   void                                                                     *
  844. *****************************************************************************/
  845. static void ScaleCB(Widget w, IGGraphicEventType EventType)
  846. {
  847.     int NewValue;
  848.  
  849.     XmScaleGetValue(w, &NewValue);
  850.     XmScaleSetValue(w, 0);
  851.     if (IGProcessEvent(EventType,
  852.                IGGlblChangeFactor * (NewValue - OldSliderVal) / 100))
  853.     IGRedrawViewWindow(); 
  854.  
  855.     OldSliderVal = 0;
  856. }
  857. /*****************************************************************************
  858. * DESCRIPTION:                                                               *
  859. *   Treats scales mouse-drag movements.                       *
  860. *                                                                            *
  861. * PARAMETERS:                                                                *
  862. *   w:          Calling scale.                                             *
  863. *   EventType:  Event represented by the calling scale.                 *
  864. *                                                                            *
  865. * RETURN VALUE:                                                              *
  866. *   void                                                                     *
  867. *****************************************************************************/
  868. static void DragCB(Widget w, IGGraphicEventType EventType)
  869. {
  870.     int NewValue;
  871.  
  872.     XmScaleGetValue(w, &NewValue);
  873.     if (IGProcessEvent(EventType,
  874.                IGGlblChangeFactor * (NewValue - OldSliderVal) / 100))
  875.         IGRedrawViewWindow();
  876.  
  877.     OldSliderVal = NewValue;
  878. }
  879.  
  880. /*****************************************************************************
  881. * DESCRIPTION:                                                               M
  882. *   Creates a horizontal SubForm.                           M
  883. *                                                                            *
  884. * PARAMETERS:                                                                M
  885. *   w:    Parent widget.                                         M
  886. *   pos:  Position of SubForm within parent form.                 M
  887. *                                                                            *
  888. * RETURN VALUE:                                                              M
  889. *   The positioned SubForm widget.                         M
  890. *                                                                            *
  891. * KEYWORDS:                                                                  M
  892. *   CreateSubForm                                        M
  893. *****************************************************************************/
  894. Widget CreateSubForm(Widget Parent, int Pos)
  895. {
  896.     return XtVaCreateManagedWidget("Form",
  897.                    xmFormWidgetClass,     Parent, 
  898.                    XmNtopAttachment,    XmATTACH_POSITION,
  899.                    XmNtopPosition,    Pos,
  900.                    XmNbottomAttachment, XmATTACH_POSITION,
  901.                    XmNbottomPosition,    Pos + 1,
  902.                    XmNleftAttachment,     XmATTACH_FORM,
  903.                    XmNrightAttachment,  XmATTACH_FORM,
  904.                    XmNresizable,     FALSE,
  905.                    NULL);
  906. }
  907.  
  908. /*****************************************************************************
  909. * DESCRIPTION:                                                               M
  910. *   A new label to an old widget.                           M
  911. *                                                                            *
  912. * PARAMETERS:                                                                M
  913. *   w:         Calling widget.                                              M
  914. *   NewLabel:  Widget's new Label.                         M
  915. *                                                                            *
  916. * RETURN VALUE:                                                              M
  917. *   void                                                                     M
  918. *                                                                            *
  919. * KEYWORDS:                                                                  M
  920. *   SetLabel                                            M
  921. *****************************************************************************/
  922. void SetLabel(Widget w, char *NewLabel)
  923.     XmString LabelText;
  924.     Arg Args[10];
  925.  
  926.     LabelText = XmStringCreate(NewLabel, "CharSet1");
  927.     XtSetArg(Args[0], XmNlabelString, LabelText);
  928.     XtSetValues(w, Args, 1);
  929.     XmStringFree(LabelText);
  930. }
  931.  
  932. /*****************************************************************************
  933. * DESCRIPTION:                                                               M
  934. *   Adds a push button to pop up menu.                        M
  935. *                                                                            *
  936. * PARAMETERS:                                                                M
  937. *   w:               Calling widget                                     M
  938. *   Label -         The Label on the push button.                 M
  939. *   Pos:           The position of the push button within the menu.         M
  940. *   FuncPtr, FuncEvent:  Call back function/event.                 M
  941. *                                                                            *
  942. * RETURN VALUE:                                                              M
  943. *   A push button widget.                                                    M
  944. *                                                                            *
  945. * KEYWORDS:                                                                  M
  946. *   AddButton                                            M
  947. *****************************************************************************/
  948. Widget AddButton(Widget Parent,
  949.          char *Label,
  950.          int Pos,
  951.          XTC FuncPtr,
  952.          XTP FuncEvent)
  953. {
  954.     Widget
  955.     Button = XtVaCreateManagedWidget(Label, 
  956.         xmPushButtonWidgetClass,    CreateSubForm(Parent, Pos),
  957.         XmNleftAttachment,         XmATTACH_FORM,
  958.         XmNrightAttachment,         XmATTACH_FORM,
  959.         NULL);
  960.  
  961.     XtAddCallback(Button, XmNactivateCallback, FuncPtr, FuncEvent);
  962.  
  963.     return Button;
  964. }
  965.  
  966. /*****************************************************************************
  967. * DESCRIPTION:                                                               M
  968. *   Adds a label widget to the pop up menu.                       M
  969. *                                                                            *
  970. * PARAMETERS:                                                                M
  971. *   w:      Calling widget.                                           M
  972. *   Label:  The Label on the Label widget.                     M
  973. *   Pos:    Widgets position within parent form.                 M
  974. *                                                                            *
  975. * RETURN VALUE:                                                              M
  976. *   The newly created Label.                                                 M
  977. *                                                                            *
  978. * KEYWORDS:                                                                  M
  979. *   AddLabel                                            M
  980. *****************************************************************************/
  981. Widget AddLabel(Widget Parent, char *Label, int Pos)
  982. {
  983.     return XtVaCreateManagedWidget(Label,
  984.             xmLabelWidgetClass,    CreateSubForm(Parent, Pos),
  985.              XmNleftAttachment,     XmATTACH_FORM,
  986.             XmNrightAttachment,     XmATTACH_FORM,
  987.             NULL);
  988. }
  989.  
  990. /*****************************************************************************
  991. * DESCRIPTION:                                                               M
  992. *   Adds a scale to the pop up menu.                           M
  993. *                                                                            *
  994. * PARAMETERS:                                                                M
  995. *   w:               Parent widget.                                          M
  996. *   pos:             Scale's position within menu.                           M
  997. *   Range:           Scale's range.                                          M
  998. *   FuncPtr, FuncEvent:  Call back function/event.                 M
  999. *                                                                            *
  1000. * RETURN VALUE:                                                              M
  1001. *   The scale widget.                                                        M
  1002. *                                                                            *
  1003. * KEYWORDS:                                                                  M
  1004. *   AddSlide                                            M
  1005. *****************************************************************************/
  1006. Widget AddSlide(Widget Parent,
  1007.         int Pos,
  1008.         int Range,
  1009.         XTC FuncPtr,
  1010.         XTP FuncEvent)
  1011. {
  1012.     Widget
  1013.     Slide = XtVaCreateManagedWidget("Slide",
  1014.             xmScaleWidgetClass,     CreateSubForm(Parent, Pos),
  1015.             XmNorientation,        XmHORIZONTAL,
  1016.             XmNminimum,          -Range,
  1017.             XmNrightAttachment,     XmATTACH_FORM,
  1018.             XmNleftAttachment,       XmATTACH_FORM,
  1019.             XmNmaximum,        Range,  NULL);
  1020.  
  1021.     XtAddCallback(Slide, XmNvalueChangedCallback, FuncPtr, FuncEvent);
  1022.     XtAddCallback(Slide, XmNdragCallback, FuncPtr, FuncEvent);
  1023.  
  1024.     return Slide;
  1025. }
  1026.  
  1027. /*****************************************************************************
  1028. * DESCRIPTION:                                                               *
  1029. *   Reads one default from X resource data base.                   *
  1030. *                                                                            *
  1031. * PARAMETERS:                                                                *
  1032. *  Entry:  The entry seeked.                                             *
  1033. *                                                                            *
  1034. * RETURN VALUE:                                                              *
  1035. *   The entry's value.                                                       *
  1036. *****************************************************************************/
  1037. static char *ReadOneXDefault(char *Entry)
  1038. {
  1039.     XrmString Type;
  1040.     XrmValue Result;
  1041.     char Line[LINE_LEN_LONG];
  1042.  
  1043.     sprintf(Line, "%s.%s", RESOURCE_NAME, Entry);
  1044.     if (XrmGetResource(XDisplay->db, Line, "Program.Name", &Type, &Result))
  1045.     return Result.addr;
  1046.     else
  1047.     return NULL;
  1048. }
  1049.  
  1050. /*****************************************************************************
  1051. * DESCRIPTION:                                                               *
  1052. *   Reads Defaults from X data base.                           *
  1053. *                                                                            *
  1054. * PARAMETERS:                                                                *
  1055. *   void                                                     *
  1056. *                                                                            *
  1057. * RETURN VALUE:                                                              *
  1058. *   void                                                                     *
  1059. *****************************************************************************/
  1060. static void ReadXDefaults(void)
  1061. {
  1062.     int i;
  1063.     XColor Color;
  1064.     char *TransBackGroundColor = ReadOneXDefault("Trans.BackGround"),
  1065.      *PanelBackGroundColor = ReadOneXDefault("Panel.BackGround"),
  1066.          *TransBorderColor = ReadOneXDefault("Trans*BorderColor"),
  1067.          *TransBorderWidthStr = ReadOneXDefault("Trans*BorderWidth"),
  1068.          *TransTextColor = ReadOneXDefault("Trans.TextColor"),
  1069.          *TransSubWinBackColor = ReadOneXDefault("Trans.SubWin.BackGround"),
  1070.          *TransSubWinBorderColor = ReadOneXDefault("Trans.SubWin.BorderColor"),
  1071.          *TransSubWinBorderWidthStr = ReadOneXDefault("Trans.SubWin.BorderWidth"),
  1072.          *TransGeometry = ReadOneXDefault("Trans.Geometry"),
  1073.          *TransCursorColorStr = ReadOneXDefault("Trans.CursorColor"),
  1074.          *ViewBackGroundColor = ReadOneXDefault("View.BackGround"),
  1075.          *ViewTextColor = ReadOneXDefault("View.TextColor"),
  1076.          *ViewBorderColor = ReadOneXDefault("View.BorderColor"),
  1077.          *ViewBorderWidthStr = ReadOneXDefault("View.BorderWidth"),
  1078.          *ViewGeometry = ReadOneXDefault("View.Geometry"),
  1079.          *ViewCursorColorStr = ReadOneXDefault("View.CursorColor"),
  1080.          *MaxColorsStr = ReadOneXDefault("MaxColors");
  1081.     if (XParseColor(XDisplay, XColorMap, "Black", &BlackColor))
  1082.     XAllocColor(XDisplay, XColorMap, &BlackColor);
  1083.  
  1084.     if (PanelBackGroundColor != NULL)
  1085.        printf("Found Panel Backgoround \n");
  1086.         
  1087.     if (TransBackGroundColor != NULL &&
  1088.     XParseColor(XDisplay, XColorMap, TransBackGroundColor, &Color) &&
  1089.     XAllocColor(XDisplay, XColorMap, &Color))
  1090.     TransBackGroundPixel = Color.pixel;
  1091.     else
  1092.     TransBackGroundPixel = BlackPixel(XDisplay, XScreen);
  1093.  
  1094.     if (TransBorderColor != NULL &&
  1095.     XParseColor(XDisplay, XColorMap, TransBorderColor, &Color) &&
  1096.     XAllocColor(XDisplay, XColorMap, &Color))
  1097.     TransBorderPixel = Color.pixel;
  1098.     else
  1099.     TransBorderPixel = WhitePixel(XDisplay, XScreen);
  1100.  
  1101.     if (TransBorderWidthStr)
  1102.     TransBorderWidth = atoi(TransBorderWidthStr);
  1103.     else
  1104.     TransBorderWidth = 1;
  1105.  
  1106.     if (TransTextColor != NULL &&
  1107.     XParseColor(XDisplay, XColorMap, TransTextColor, &Color) &&
  1108.     XAllocColor(XDisplay, XColorMap, &Color))
  1109.     TransTextPixel = Color.pixel;
  1110.     else
  1111.     TransTextPixel = WhitePixel(XDisplay, XScreen);
  1112.  
  1113.     if (TransSubWinBackColor != NULL &&
  1114.     XParseColor(XDisplay, XColorMap, TransSubWinBackColor, &Color) &&
  1115.     XAllocColor(XDisplay, XColorMap, &Color))
  1116.     TransSubWinBackPixel = Color.pixel;
  1117.     else
  1118.     TransSubWinBackPixel = BlackPixel(XDisplay, XScreen);
  1119.  
  1120.     if (TransSubWinBorderColor != NULL &&
  1121.     XParseColor(XDisplay, XColorMap, TransSubWinBorderColor, &Color) &&
  1122.     XAllocColor(XDisplay, XColorMap, &Color))
  1123.     TransSubWinBorderPixel = Color.pixel;
  1124.     else
  1125.     TransSubWinBorderPixel = WhitePixel(XDisplay, XScreen);
  1126.  
  1127.     if (TransSubWinBorderWidthStr)
  1128.     TransSubWinBorderWidth = atoi(TransSubWinBorderWidthStr);
  1129.     else
  1130.     TransSubWinBorderWidth = 1;
  1131.  
  1132.     if (IGGlblTransPrefPos &&
  1133.     sscanf(IGGlblTransPrefPos, "%d,%d,%d,%d",
  1134.            &TransPosX, &TransWidth, &TransPosY, &TransHeight) == 4) {
  1135.     TransWidth -= TransPosX;
  1136.     TransHeight -= TransPosY;
  1137.     TransHasSize = TransHasPos = TRUE;
  1138.     }
  1139.     else if ((IGGlblTransPrefPos == NULL || strlen(IGGlblViewPrefPos) == 0) &&
  1140.          TransGeometry) {
  1141.     i = XParseGeometry(TransGeometry, &TransPosX, &TransPosY,
  1142.                                   &TransWidth, &TransHeight);
  1143.     TransHasPos = i & XValue && i & YValue;
  1144.     TransHasSize =  i & WidthValue && i & HeightValue;
  1145.     }
  1146.     else
  1147.         TransHasSize = TransHasPos = FALSE;
  1148.  
  1149.     if (TransCursorColorStr != NULL &&
  1150.     XParseColor(XDisplay, XColorMap, TransCursorColorStr, &Color) &&
  1151.     XAllocColor(XDisplay, XColorMap, &Color)) {
  1152.     TransCursorColor = (XColor *) IritMalloc(sizeof(XColor));
  1153.     *TransCursorColor = Color;
  1154.     }
  1155.     else
  1156.     TransCursorColor = NULL;
  1157.  
  1158.     if (ViewBackGroundColor &&
  1159.     XParseColor(XDisplay, XColorMap, ViewBackGroundColor, &Color) &&
  1160.     XAllocColor(XDisplay, XColorMap, &Color))
  1161.     ViewBackGroundPixel = Color.pixel;
  1162.     else
  1163.     ViewBackGroundPixel = BlackPixel(XDisplay, XScreen);
  1164.  
  1165.     if (ViewBorderColor &&
  1166.     XParseColor(XDisplay, XColorMap, ViewBorderColor, &Color) &&
  1167.     XAllocColor(XDisplay, XColorMap, &Color))
  1168.     ViewBorderPixel = Color.pixel;
  1169.     else
  1170.     ViewBorderPixel = WhitePixel(XDisplay, XScreen);
  1171.  
  1172.     if (ViewTextColor != NULL &&
  1173.     XParseColor(XDisplay, XColorMap, ViewTextColor, &Color) &&
  1174.     XAllocColor(XDisplay, XColorMap, &Color))
  1175.     ViewTextPixel = Color.pixel;
  1176.     else
  1177.     ViewTextPixel = WhitePixel(XDisplay, XScreen);
  1178.  
  1179.     if (ViewBorderWidthStr)
  1180.     ViewBorderWidth = atoi(ViewBorderWidthStr);
  1181.     else
  1182.     ViewBorderWidth = 1;
  1183.  
  1184.     if (IGGlblViewPrefPos &&
  1185.     sscanf(IGGlblViewPrefPos, "%d,%d,%d,%d",
  1186.            &ViewPosX, &ViewWidth, &ViewPosY, &ViewHeight) == 4) {
  1187.     ViewWidth -= ViewPosX;
  1188.     ViewHeight -= ViewPosY;
  1189.     ViewHasSize = ViewHasPos = TRUE;
  1190.     }
  1191.     else if ((IGGlblViewPrefPos == NULL || strlen(IGGlblViewPrefPos) == 0) &&
  1192.          ViewGeometry) {
  1193.     i = XParseGeometry(ViewGeometry, &ViewPosX, &ViewPosY,
  1194.                                  &ViewWidth, &ViewHeight);
  1195.     ViewHasPos = i & XValue && i & YValue;
  1196.     ViewHasSize = i & WidthValue && i & HeightValue;
  1197.     }
  1198.     else
  1199.     ViewHasSize = ViewHasPos = FALSE;
  1200.  
  1201.     if (ViewCursorColorStr != NULL &&
  1202.     XParseColor(XDisplay, XColorMap, ViewCursorColorStr, &Color) &&
  1203.     XAllocColor(XDisplay, XColorMap, &Color)) {
  1204.     ViewCursorColor = (XColor *) IritMalloc(sizeof(XColor));
  1205.     *ViewCursorColor = Color;
  1206.     }
  1207.     else
  1208.     ViewCursorColor = NULL;
  1209.  
  1210.     if (MaxColorsStr)
  1211.     MaxColors = atoi(MaxColorsStr);
  1212.     else
  1213.     MaxColors = IG_MAX_COLOR;
  1214. }
  1215.  
  1216. /*****************************************************************************
  1217. * DESCRIPTION:                                                               M
  1218. *   Makes some sound.                                                        M
  1219. *                                                                            *
  1220. * PARAMETERS:                                                                M
  1221. *   None                                                                     M
  1222. *                                                                            *
  1223. * RETURN VALUE:                                                              M
  1224. *   void                                                                     M
  1225. *                                                                            *
  1226. * KEYWORDS:                                                                  M
  1227. *   IGIritBeep                                                               M
  1228. *****************************************************************************/
  1229. void IGIritBeep(void)
  1230. {
  1231.     XBell(XDisplay, 0);
  1232. }
  1233.  
  1234. /*****************************************************************************
  1235. * DESCRIPTION:                                                               M
  1236. *   Optionally construct a state pop up menu for the driver, if has one.     M
  1237. *                                                                            *
  1238. * PARAMETERS:                                                                M
  1239. *   None                                                                     *
  1240. *                                                                            *
  1241. * RETURN VALUE:                                                              M
  1242. *   void                                                                     M
  1243. *                                                                            *
  1244. * KEYWORDS:                                                                  M
  1245. *   IGCreateStateMenu                                                        M
  1246. *****************************************************************************/
  1247. void IGCreateStateMenu(void)
  1248. {
  1249. }
  1250.  
  1251.